﻿using System;
using FluentValidation.TestHelper;
using GiveAQuizSite.Models;
using GiveAQuizSite.Validation;
using NUnit.Framework;

namespace GiveAQuizSite.Tests.Validation
{
  [TestFixture]
  public class ResetPasswordValidatorTest
  {
    public ResetPasswordValidator Validator
    {
      get;
      private set;
    }

    [TestFixtureSetUp]
    public void InitializeTests()
    {
      Validator = new ResetPasswordValidator();
    }

    [Test]
    public void Custom_should_have_error_when_username_is_null_and_email_is_null()
    {
      var model = new ResetPasswordViewModel { UserName = null, Email = null }; 
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_empty_and_email_is_null()
    {
      var model = new ResetPasswordViewModel { UserName = String.Empty, Email = null };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_blank_and_email_is_null()
    {
      var model = new ResetPasswordViewModel { UserName = " ", Email = null };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_null_and_email_is_empty()
    {
      var model = new ResetPasswordViewModel { UserName = null, Email = String.Empty };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_empty_and_email_is_empty()
    {
      var model = new ResetPasswordViewModel { UserName = String.Empty, Email = String.Empty };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_blank_and_email_is_empty()
    {
      var model = new ResetPasswordViewModel { UserName = " ", Email = String.Empty };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_null_and_email_is_blank()
    {
      var model = new ResetPasswordViewModel { UserName = null, Email = " " };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_empty_and_email_is_blank()
    {
      var model = new ResetPasswordViewModel { UserName = String.Empty, Email = " " };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_have_error_when_username_is_blank_and_email_is_blank()
    {
      var model = new ResetPasswordViewModel { UserName = " ", Email = " " };
      Validator.ShouldHaveValidationErrorFor(cr => cr.UserName, model);
    }

    [Test]
    public void Custom_should_not_have_error_when_username_is_valid()
    {
      var model = new ResetPasswordViewModel { UserName = "foo", Email = null };
      Validator.ShouldNotHaveValidationErrorFor(cr => cr.UserName, model);
      Validator.ShouldNotHaveValidationErrorFor(cr => cr.Email, model);
    }

    [Test]
    public void Custom_should_not_have_error_when_email_is_valid()
    {
      var model = new ResetPasswordViewModel { UserName = null, Email = "foo@bar.com" };
      Validator.ShouldNotHaveValidationErrorFor(cr => cr.UserName, model);
      Validator.ShouldNotHaveValidationErrorFor(cr => cr.Email, model);
    }

    [Test]
    public void Custom_should_have_error_when_email_is_invalid()
    {
      var model = new ResetPasswordViewModel { UserName = null, Email = "foo" };
      Validator.ShouldNotHaveValidationErrorFor(cr => cr.UserName, model);
      Validator.ShouldHaveValidationErrorFor(cr => cr.Email, model);
    }
  }
}
